<template>
 <div class="product-item" @click="itemClick">
      <img :src="showImage" @load="imagesLoad">
    <div class="product-item-text">
        <p>{{ productItem.title }}</p>
     <div class="product-item-bottomText">
         <div class="jiage">
           <span >￥{{ productItem.price }}</span>
         </div>
         <div class="shouchang">
             <i class="icons"></i>
              <span class="shouc">{{ productItem.cfav }}</span>
         </div>
         
       </div>
    </div>
 </div>
</template>

<script>
export default {
    name:'ProductListItem',
    props: {
      productItem: {
          type: Object,
          default() {
              return {}
          }
      },
    },
    computed: {
         showImage() {
             return this.productItem.img || this.productItem.image || this.productItem.show.img
         } 
    },
    methods: {
        // 监听图片是否加载完成触发事件
        imagesLoad() {
          if (this.$route.path.indexOf('/home')){
             this.$bus.$emit('itemImagesLoad')
          }else if(this.$route.path.indexOf('/detail')){
             this.$bus.$emit('itemImagesLoad')
          }else if(this.$route.path.indexOf('./category')){
              this.$bus.$emit('itemImagesLoad')
          }
        },
        //  跳转详细页面
        itemClick() {
            this.$router.push('/detail/' + this.productItem.iid)
        }
    }
}
</script>

<style scoped>
.product-item{
    box-sizing: border-box;
    width: 48%;
    padding-bottom: 45px;
    position: relative;
}
.product-item img{
    width: 100%;
    border-radius: 8px;
}
.product-item-text{
    position: absolute;
    left: 0;
    right: 0;
    font-size: 12px;
    /* bottom: 2px; */
    overflow: hidden;
    text-align: center;
}
.product-item-text p{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
}
.product-item-bottomText{
    /* background-color: #000; */
    display: flex;
    height: 20px;
    line-height: 20px;
}
.product-item-bottomText .jiage{
    flex: 1;
    color:#d43c9c;
}
.product-item-bottomText .shouchang{
    width: 70px;
}
.product-item-bottomText .shouchang .icons{
    display: inline-block;
    width: 20px;
    height: 20px;
    background: url(~assets/images/product/souc.png) no-repeat;
    background-size: cover;
    vertical-align: bottom;
}
.product-item-bottomText .shouchang .shouc{
    float: right;
    margin: 0 20px 0 3px;
}
</style>